import { Singleton } from "../../../util/decorate/Singleton";
import { ccs } from "../../../util/services";
import { ItemFactory } from "../Item/itemFactory";
import { assetsBag } from "./assetsBag";
import { cardBag } from "./cardBag";
import { companyBag } from "./companyBag";
import { fashionBag } from "./fashionBag";
import { figureBag } from "./figureBag";
import { itemsBag } from "./itemsBag";


// @Singleton
export class BagM {
    itemsBag: itemsBag = null; //消费品背包
    fashionBag: fashionBag = null; //
    figureBag: figureBag = null;
    assetsBag: assetsBag = null;
    cardBag: cardBag = null;
    companyBag: companyBag = null;
    //背包管理
    constructor() {
        this.itemsBag = new itemsBag({itemTypes: ["food", "tec"], bagType: "house"});
        this.fashionBag = new fashionBag({itemTypes: ["fashion"], bagType: "fashion"});
        this.figureBag = new figureBag({itemTypes: ["hero"], bagType: "hero"});
        this.assetsBag = new assetsBag({itemTypes: ["car", "house"], bagType: "assets"});
        this.cardBag = new cardBag({itemTypes: ["card"], bagType: "card"}); //永久资产
        this.companyBag = new companyBag({itemTypes: ["company"], bagType: "company"}); //永久资产
    }

    loadBag(bags) {
        //加载本地数据背包
        for(let key in bags ){
            this[key].loadItems(bags[key]);
        }
    }    
    clearBag() {
        let bags = ccs.gf.getLocalData("bag");
        for(let key in bags ){
            this[key].bag.items.forEach(val => {
                this[key].delItem(val.id);
            })
        }
    }
}